﻿using LanguagePolish.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;

namespace LanguagePolish.EntityModel
{
    partial class Teacher
        : BaseViewModelErrorInfo     // добавляем возможность использования оповещения.
    {
        public string AllClasses 
        {
            get { return string.Join(", ", Classes.Select(c => c.ClassName)); }
        }

        public override void CreateRules()
        {
            AddRule("Name", () => string.IsNullOrWhiteSpace(Name), "'Name' can't be empty!");
        }

        private BitmapImage image;

        public BitmapImage PhotoImage
        {
            get
            {
                if (image == null && Photo != null)
                {
                    image = Helper.ImageFromBuffer(Photo);
                }
                return image;
            }
            set
            {
                image = value;
                Photo = value != null ? Helper.BufferFromImage(image) : null;
            }
        }    
    }    

}
